<template>
	<view>
		<view class="bg-white padding">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="button"
				class="bg-white " activeColor="#00ac04"></uni-segmented-control>
		</view>
		<view class="  padding-sm  bg-white" style="margin-top: -20rpx;display: flex;">
			<view style="width: 50%;margin-right: 10rpx;">
				<uni-data-select v-model="queryForm.orgIds_EQ" :localdata="orgList" @change="getList"
					placeholder="按院子查询"></uni-data-select>
			</view>
			<view style="border: 1px solid #e5e5e5;border-radius: 10rpx;">
				<uni-easyinput v-model="queryForm.uid_LIKE" :inputBorder="false" placeholder="按用户查询(后四位)"
					@blur="getList"></uni-easyinput>
			</view>
		</view>

		<view class="  padding-sm margin-top-sm ">
			<view v-for="item in list" class="margin-bottom bg-white padding-sm radius">
				<view>
					<view style="display: flex;  justify-content: space-between;">
						<view class="font-title font-34rpx">
							{{item.status==0?'未付款':item.status==1?'已预约':item.status==2?'已完成':item.status==3?'已取消':'未知'}}
						</view>
						<view class="font-content font-12">{{item.shopTitle}}---{{item.title}}</view>
					</view>
					<view style="display: flex;  justify-content: space-between;" class="margin-top-sm">
						<view class="font-content font-12">
							金额:{{item.price}}

						</view>
						<view class="font-content font-12">{{item.date}}</view>
					</view>
					<view style="display: flex;  justify-content: space-between;" class="margin-top-sm">
						<view class="font-content font-12">
							{{item.dingjinStatus==0?'未付押金':item.dingjinStatus==1?'已付押金':item.dingjinStatus==2?'已退款':item.dingjinStatus==3?'已退款':'未知'}}
						</view>
						<view class="font-content font-12">押金:{{item.dingjin/100}}</view>
					</view>
					<view style="display: flex;  justify-content: space-between;" class="margin-top-sm">

						<view class="font-content font-12">用户id:{{item.uid}}</view>
					</view>
				</view>
				<view class=" margin-top-sm" style="display: flex;justify-content: space-between;">
					<view>
						<!-- <button v-if="item.status==0" plain size="mini" class="login-btn cu-btn block   bg-red "
							style="color: red;border-color:red " @click="orderCancel(item.id)">取消</button> -->
					</view>
					<view style="display: flex;">
						<button v-if="item.status==1" size="mini"
							class="login-btn cu-btn block  margin-right-xs bg-red " style="background-color: #00ac04;"
							@click="orderConfirm(item.id)">确认到访</button>
						<button v-if="item.status==1" plain size="mini"
							class="login-btn cu-btn block  margin-right-xs bg-red " style="color: red;border-color:red "
							@click="orderCancel(item.id)">取消</button>
						<button v-if="item.dingjinStatus==1" plain size="mini"
							class="login-btn cu-btn block margin-right-xs  bg-red " style="color: red;border-color:red "
							@click="refund(item.id)">退款</button>


						<button v-if="item.userModel.mobile!=null&&item.userModel.mobile!=''" plain size="mini"
							class="login-btn cu-btn block margin-right-xs  bg-red " style="color: red;border-color:red "
							@click="call(item.userModel)">联系用户</button>


					</view>


				</view>
			</view>
			<view v-if="list.length==0" class="juzhong">
				暂无数据
			</view>
		</view>
	</view>
</template>
<script>
	import storage from '@/utils/storage'
	import {
		getList,
		refund,
		orderCancel,
		orderConfirm
	} from "@/api/shop/userorder/ShopUserOrderManagementApi.js"
	export default {

		data() {
			return {
				items: ['全部', '待到访', '已使用', '退款/取消'],
				current: 0,
				user: null,
				list: [],
				queryForm: {
					pageNo: 1,
					pageSize: 10,
					uid_EQ: "",
					status_EQ: "",
					date_ORDER: "DESC",

				},
				orgList: [],
			};
		},
		onReachBottom() {
			this.queryForm.pageNo++
			this.listAdd()
		},
		onLoad(o) {

			this.current = parseInt(o.type)
			this.queryForm.uid_EQ = this.$store.state.user.id
			this.$forceUpdate()
			this.init()

		},
		methods: {
			call(data) {


				uni.makePhoneCall({
					phoneNumber: data.mobile,
					success: function() {
						console.log('拨打电话成功');
					},
					fail: function(error) {
						console.log('拨打电话失败', error);
					}
				});

			},
			init() {
				this.setorgList()
				this.getList()
			},
			setorgList() {
				let list = this.$storage.getItem("miniappinfo").orgList
				let list2 = []
				for (let s of list) {
					list2.push({
						text: s.orgName,
						value: s.orgIds
					})
				}
				this.orgList = list2
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;

					if (this.current == 0) {
						this.queryForm.status_EQ = null
					}
					if (this.current == 1) {
						this.queryForm.status_EQ = 1
					}
					if (this.current == 2) {
						this.queryForm.status_EQ = 2
					}
					if (this.current == 3) {
						this.queryForm.status_EQ = 3
					}

					this.queryForm.pageNo = 1
					this.getList()

				}
			},
			async getList() {
				this.queryForm.pageNo = 1
				let {
					data
				} = await getList(this.queryForm);
				this.list = data.rows
			},

			async listAdd() {
				let {
					data
				} = await getList(this.queryForm);
				for (let s of data.rows) {
					this.list.push(s)
				}
			},
			refund(id) {
				let _this = this
				uni.showModal({
					title: '提示',
					content: '您正在退还押金',
					success: async function(res) {
						if (res.confirm) {
							let {
								data,
								msg
							} = await refund({
								id: id
							});

							uni.showModal({
								title: '成功',
								content: msg,
								showCancel: false
							})

							_this.getList()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});


			},

			async orderCancel(id) {
				let _this = this
				uni.showModal({
					title: '您正在取消订单',
					content: '请先与顾客协商,确认取消吗',
					success: async function(res) {
						if (res.confirm) {
							let {
								data,
								msg
							} = await orderCancel({
								id: id
							});

							uni.showModal({
								title: '成功',
								content: msg,
								showCancel: false
							})

							_this.getList()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});




			},
			async orderConfirm(id) {
				let _this = this
				uni.showModal({
					title: '提示',
					content: '您正在确认到访',
					success: async function(res) {
						if (res.confirm) {
							let {
								data,
								msg
							} = await orderConfirm({
								id: id
							});

							uni.showModal({
								title: '成功',
								content: msg,
								showCancel: false
							})

							_this.getList()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});




			}
		}
	};
</script>
<style>
	page {
		/* background-color: white; */
	}
</style>